<?php 
if($_GET['act']=="get_special_tpl" && $_GET['templates_id']>0){
	$sql = "select tpl_con from ".SHARESPECIALTPL." where id='{$_GET['templates_id']}'";
	$db->query($sql);
	$res = $db->fetchField('tpl_con');
	exit($res);
}
if($_POST['act']){
	unset($_GET['s']);
	unset($_GET['m']);
	unset($_GET['operation']);
	if($_POST['act'] == 'save'){//新增
		$sql = "insert into ".SHARESPECIAL." (cat_id,title,pic,favorite_num,share_num,visit_num,virtual_favorite_num,virtual_share_num,virtual_visit_num,templates_id,`desc`,`status`,create_user,`share_title`,`share_pic`,`share_desc`) values('{$_POST['cat_id']}','{$_POST['title']}','{$_POST['pic']}','{$_POST['virtual_favorite_num']}','{$_POST['virtual_share_num']}','{$_POST['virtual_visit_num']}','{$_POST['virtual_favorite_num']}','{$_POST['virtual_share_num']}','{$_POST['virtual_visit_num']}','{$_POST['templates_id']}','{$_POST['desc']}','{$_POST['status']}','{$_SESSION['ADMIN_USER']}','{$_POST['share_title']}','{$_POST['share_pic']}','{$_POST['share_desc']}')";
		$db->query($sql);
	}
	if($_POST['act'] == 'edit' && $_POST['id']>0){//编辑
		$sql = "update ".SHARESPECIAL." set cat_id='{$_POST['cat_id']}',title='{$_POST['title']}',pic='{$_POST['pic']}',favorite_num=(favorite_num-virtual_favorite_num+{$_POST['virtual_favorite_num']}),share_num=(share_num-virtual_share_num+{$_POST['virtual_share_num']}),visit_num=(visit_num-virtual_visit_num+{$_POST['virtual_visit_num']}),virtual_favorite_num='{$_POST['virtual_favorite_num']}',virtual_share_num='{$_POST['virtual_share_num']}',virtual_visit_num='{$_POST['virtual_visit_num']}',templates_id='{$_POST['templates_id']}',`desc`='{$_POST['desc']}',`status`='{$_POST['status']}',`share_title`='{$_POST['share_title']}',`share_pic`='{$_POST['share_pic']}',`share_desc`='{$_POST['share_desc']}' where id='{$_POST['id']}'";
		$db->query($sql);
	}
	unset($_GET['editid']);
	$getstr=implode('&',convert($_GET));
	msg("?m=share_special&s=share_special_list.php&$getstr");
}
if($_GET['operation']=='edit' && $_GET['editid']>0){
	$sql = "select * from ".SHARESPECIAL." where id='{$_GET['editid']}'";
	$db->query($sql);
	$de = $db->fetchRow();
}
//模板数据
$sql = "select * from ".SHARESPECIALTPL." where status>0";
$db->query($sql);
$de['temp'] = $db->getRows();

//分类数据
$sql = "select id,cat_name from ".SHARESPECIALCAT." where status>0";
$db->query($sql);
$cat = $db->getRows();
$catArr = [];
foreach ($cat as $v)
{
    $catArr[$v['id']] = $v['cat_name'];
}

$tpl->assign('catArr',$catArr);
$tpl->assign('de',$de);
$tpl->assign("config",$config);
$tpl->display("share_special_add_edit.htm");
?>